#include <iostream>
#include <vector>
#include <string>

using namespace std;

string addStrings(string num1, string num2) {
    int carry = 0, len = max(num1.size(), num2.size()); string ret;
    for(int i = 0; i < len; i++){
        char at = (int(num1.size())-i > 0 ? num1[num1.size()-1-i] : '0'), bt = (int(num2.size())-i > 0 ? num2[num2.size()-1-i] : '0'),
             t = at + bt - '0' + carry;
        if(t > '9'){
            ret.insert(ret.begin(), t-10);
            carry = 1;
        }else{
            ret.insert(ret.begin(), t);
            carry = 0;
        }
    }
    return carry == 1 ? "1" + ret : ret;
}

string singleMul(string num1, char c){
    int carry = 0; string ret;
    for(int i = 0; i < num1.size(); i++){
        int t = (num1[num1.size()-1-i]-'0') * (c-'0') + carry;
        if(t > 9){
            ret.insert(ret.begin(), t%10+'0');
            carry = t/10;
        }else{
            ret.insert(ret.begin(), t+'0');
            carry = 0;
        }
    }
    return carry == 0 ? ret : to_string(carry) + ret;
}

string multiply(string num1, string num2) {
    vector<string> res; string ret = "0";
    if(num1 == "0" || num2 == "0") return "0";
    for(int i = 0; i < num2.size(); i++){
        res.push_back(singleMul(num1, num2[num2.size()-1-i]));
        for(int j = 0; j < i; j++) res[i].push_back('0');
    }
    for(int i = 0; i < res.size(); i++){
        ret = addStrings(ret, res[i]);
    }
    return ret;
}

int main(){
    string num1 = "123", num2 = "456";
    cout << multiply(num1, num2) << endl;
    return 0;
}
